import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/model/cook_info_model.dart';
import 'package:flutter_douban/main_page/home/detail/page/cook_detail_page.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';
import 'avatar_role_name.dart';
import 'collection_image.dart';

class CookImagePage extends StatefulWidget {
  final CookInfoModel model;
  const CookImagePage({Key? key,required this.model}) : super(key: key);

  @override
  _CookImagePageState createState() => _CookImagePageState();
}

class _CookImagePageState extends State<CookImagePage> {
  @override
  Widget build(BuildContext context) {
    double _height = 0;
    if(widget.model.ph == null || widget.model.ph == 'null'){
      _height = (MediaQuery.of(context).size.width/3*2) as double;
    }else if(widget.model.ph == widget.model.pw){
      _height = (MediaQuery.of(context).size.width) as double;
    }else{
      _height = (int.parse(widget.model.ph)*MediaQuery.of(context).size.width / int.parse(widget.model.pw)) as double;
    }

    List<Widget> widgetList = [];
    widgetList.add(
      InkWell(
        child: CachedImage(
          url: widget.model.img!,
          width: MediaQuery.of(context).size.width,
          height: _height,
        ),
        onTap: () {
          Navigator.of(context).push(MaterialPageRoute(builder: (_) {
            return CookDetailPage(id: widget.model.id!,imgUrl: widget.model.img!,);
          }));
        },
      ),
    );
    if(widget.model.video_url?.isNotEmpty == true){
      /// 视频
      widgetList.add(
          Positioned(
            bottom: 5,
            right: 5,
            child: Image.asset(
              'assets/images/common/cell_video_play@2x.png',
              width: 32,
              height: 32,
            ),
          )
      );
    }

    return Container(
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          /// 用户头像条
          AvatarRoleName(model: widget.model.u,),
          /// 中间图片
          Stack(
            children: widgetList,
          ),

          /// 收藏用户头像 和 点赞 评论...按钮
          CollectionImageView(model: widget.model,),
          Container(
            margin: EdgeInsets.only(left: 10),
            child: Text(
              widget.model.t!,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                fontSize: 15,
                color: AppColors.deepTextColor,
              ),
            ),
          ),
          SizedBox(height: 20,)
        ],
      ),
    );
  }
}
